import React from 'react'

// export default class A extends React.Component {
//   state={count: 0}

//   add = () => {
//     this.setState(state => ({count: state.count+1}))
//   }
//   render() {
//     return (
//       <>
//         <div>求和是{this.state.count}</div>
//         <button onClick={this.add}>+1</button>
//       </>
//     )
//   }
// }

function A() {
  const [count,setCount] = React.useState(0);
  console.log(count);
  function add() {
    // setCount(count+1)
    setCount(count => count+1)
  }
  return (
        <>
          <div>求和是{count}</div>
          <button onClick={add}>+1</button>
        </>
  )
}


export default A